package work20250104;

import java.util.ArrayList;

/**
 * @author zdl
 * @date 2025/1/4
 */
class Animal{
    public void play(){};
}
class Dog extends Animal{
    @Override
    public void play() {
        System.out.println("狗会玩儿");
    }
}
class Cat extends Animal{
    @Override
    public void play() {
        System.out.println("猫会玩儿");
    }
}
class Pig extends Animal{
    @Override
    public void play() {
        System.out.println("猪会玩儿");
    }
}
public class Demo9 {
    public static void main(String[] args) {
        /**
         * 4、定义动物父类,子类狗,猫类等，动物类有方法play，子类重写方法,以展现不同的动物玩耍方法，
         * 然后测试类中定义一个动物数组,存储多种动物,比如猪狗猫等，然后遍历数 组,执行每种动物玩耍方法（10分）
         */
        ArrayList<Animal> list = new ArrayList<>();
        list.add(new Dog());
        list.add(new Cat());
        list.add(new Pig());
        for (Animal animal : list) {
            animal.play();
        }
        System.out.println("======");
        Animal[] animals = new Animal[3];
        animals[0] = new Pig();
        animals[1] = new Dog();
        animals[2] = new Cat();
        for (Animal animal : animals) {
            animal.play();
        }
    }
}
